from tornado import web, ioloop, httpserver
import tornado.options
from tornado.options import options
import base
'''其他包'''
import os
import json
from api.product import product_url
from api.wechat import wechat_url
from api.login import login_url
from api.config import config_url
from api.user import user_url
from api.order import order_url
from api.bill import bill_url
import base64
import uuid


'''为options定义属性'''
tornado.options.define('port', type=int, default=8090, help='服务器端口')
if __name__ == '__main__':
    tornado.options.parse_command_line()
    current_path = os.path.dirname(__file__)
    setting = dict(
        debug=True,
        static_path=os.path.join(current_path, 'webapp'),
        cookie_secret=b'DFI/357oTDG9Qh/QTsu8hhMn8wLh3ULsl8OYrmnNxPk='
    )
    app = web.Application(
        wechat_url +
        login_url +
        order_url +
        user_url + 
        product_url + 
        bill_url + 
        config_url + [
            (r'/(.*)', web.StaticFileHandler,
             dict(path=os.path.join(current_path, 'webapp'),
                  default_filename='index.html')
             ),
        ], **setting)
    '''创建httpserver实例'''
    http_server = httpserver.HTTPServer(app)
    '''这里只是绑定，还未监听'''
    http_server.listen(options.port)
    '''启动io循环'''
    ioloop.IOLoop.current().start()
